import { http } from "@/api/api"

export default {
	namespaced: true,
	state: {
		config: "",
		sign: window.location.search.replace(/\?/g, "")
	},
	getters: {
		config: state => state.config
	},
	mutations: {
		setConfig(state, data) {
			state.config = data
		}
	},
	actions: {
		// 获取网站配置信息
		async getWebsiteConfigInfo({ commit, dispatch, getters, state }) {
			const result = await new Promise((resolve, reject) => {
				http("common.config")
					.then(res => {
						if (res.code === 1) {
							document.title = res.data.system.name
							commit("setConfig", res.data.system)
							resolve(res)
						} else {
							reject(res)
						}
					})
					.catch(err => {
						reject(err)
					})
			})
			return result
		}
	}
}
